package com.example.smartf.repository.mysql;

import com.example.smartf.model.mysql.Automaticplan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface AutomaticplanRepository extends JpaRepository<Automaticplan,String> {

    public List<Automaticplan> findAllByDeviceID(String DeviceID);

    public Automaticplan findByPlanID(Integer planID);

    @Transactional
    @Modifying
    @Query("update Automaticplan set hour_c = :hour_c , min_c = :min_c , ec = :ec , light = :light , pump_time = :pump_time , fan_time = :fan_time where planID = :planID")
    public int updateAutomaticPlan(int planID , int hour_c , int min_c , int ec , int light , int pump_time , int fan_time );

    @Transactional
    @Modifying
    @Query("update Automaticplan set states = :states where planID = :planID")
    public int updatePlanstate(int states, int planID);

    @Transactional
    public int deleteByPlanID(Integer PlanID);


}
